home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl5
- #
- # mrouted.cgi
- #
- # Copyright 1988-1996 Silicon Graphics, Inc.
- # All rights reserved.
- #
- # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- # the contents of this file may not be disclosed to third parties, copied or
- # duplicated in any form, in whole or in part, without the prior written
- # permission of Silicon Graphics, Inc.
- #
- # RESTRICTED RIGHTS LEGEND:
- # Use, duplication or disclosure by the Government is subject to restrictions
- # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- # rights reserved under the Copyright Laws of the United States.
- #
- # $Id: mrouted.frm,v 1.30 1997/06/19 22:26:26 shotes Exp $
-
- require "/usr/OnRamp/lib/OnRamp.pm";
- require "/usr/OnRamp/lib/java.pm";
-
- $conf = "/etc/mrouted.conf";
- $options = "/etc/config/mrouted.options";
- $dummy = "/etc/mrouted.conf.tmp";
- $data = "/etc/mrouted.conf.data";
- $myname = "mrouted.cgi";
- $title = "Multicast Routing";
-
- if ($ENV{'HTTP_USER_AGENT'} =~ /Mozilla\/2/) { $br_index = 1; }
- else { $br_index = 0; }
-
- $js =
- "br_index = $br_index;
- $js_standard
- $js_error_box
- $js_ip
- function checkForm(form) {
- if (form.emr[br_index].checked && form.tun[br_index].checked) { // radio buttons are backwards
- if (!testAddress(form.rip)) return (false);
- }
- return (true);
- }
- function testAddress(Ctrl) {
- if (Ctrl.value == \"\") {
- errorBox (Ctrl, \"The remote IP address is required.\");
- return (false);
- }
- if (!testIPaddress(Ctrl.value,false)) {
- errorBox (Ctrl, \"The remote IP address \" + Ctrl.value
- + \" \\nis invalid.\");
- return (false);
- }
- return (true);
- }";
-
- print "Content-type: text/html\n\n";
-
- &get_fields;
-
- &getInfo;
-
- $help = $document_root . $ENV{"SCRIPT_NAME"};
- $help =~ s/cgi$/hlp/;
- exec $help if ($fld{'help'} eq "Help");
-
- if ($fld{"doit"} eq "Ok") {
- if ($fld{'tun'} eq 'Yes' && $fld{'emr'} eq 'Yes') { &formValidation; }
- &edit;
- &getInfo;
- }
-
- if (-e "/usr/etc/mrouted") { &generic; }
- else {
- &title_block($title);
- &header_block($title);
- print "<i>Multicast routing software not installed. Install
- subsystem </i><b>eoe.sw.ipgate</b><i> from the distribution CD.</i>";
- }
-
- sub error {
- &error_block($_[0]);
- %val = %fld;
- &generic;
- exit 0;
- }
-
- sub edit {
- system("/etc/killall", "mrouted");
- if ($fld{'emr'} eq 'Yes') {
- if ($val{'emr'} eq 'No') { $message = "Multicast routing enabled. "; }
- if ($fld{'tun'} eq 'Yes') {
- &writeTunnel;
- $message .= "Tunnel information updated.";
- }
- else {
- &turnOffTunnel;
- $message .= "Tunnel disabled.";
- }
- &restartDeamon("mrouted","/usr/etc/mrouted",$options);
- system("/etc/chkconfig", "mrouted", "on");
- } else {
- system("/etc/chkconfig", "mrouted", "off");
- if ($val{'emr'} eq 'Yes') {
- $message = "Multicast routing disabled.";
- } else { $message = "No change made."; }
- $val{'emr'} = "No";
- }
- }
-
- sub turnOffTunnel {
- ($dummy,$local) = split(/ /,$fld{'int'});
-
- open(IN,"< $conf");
- open(OUT,"> $dummy");
- while(<IN>) {
- $line = $_;
- @items = split(/\s+/,$line);
- if ($items[0] eq "tunnel" && $items[1] eq $local) {
- $line = "# $line";
- }
- print OUT $line;
- }
- close(IN);
- close(OUT);
- rename($dummy,$conf);
- }
-
- sub writeTunnel {
- ($skip,$local) = split(/ /,$fld{'int'});
-
- open(IN,"< $conf");
- open(OUT,"> $dummy");
- $printed = 0;
- while(<IN>) {
- @items = split(/\s+/);
- if ($items[0] ne "tunnel") { print OUT $_; }
- else {
- if ($items[1] eq $local) {
- if ($items[2] eq $fld{'rip'}) {
- print OUT $_;
- $printed = 1;
- } else {
- print OUT "# $_";
- print OUT "tunnel $local $fld{'rip'}\n";
- $printed = 1;
- }
- }
- }
- }
- if (!$printed) { print OUT "tunnel $local $fld{'rip'}\n"; }
- close(OUT);
- close(IN);
- rename($dummy,$conf);
- }
-
- sub restartDeamon {
- $command = "$_[1] ";
- open(IN,"< $_[2]");
- while(<IN>) { chop($_); $command .= " $_"; }
- close(IN);
- system($command);
- }
-
- sub formValidation {
- &error("Remote IP address required.") if $fld{'rip'} eq "";
- if (&check_ipaddr($fld{'rip'})) {
- &error("Invalid remote IP address");
- &generic;
- exit 0;
- }
- }
-
- sub generic {
- &js_title_block($title,$js);
- &header_block($title);
-
- print "<i>$message</i>";
-
- print qq|<form method=post name="StandardForm" action="$myname" onSubmit="return runSubmit()">|;
-
- print "<center><table cellpadding=5 width=450>";
-
- print "<tr><th align=left>Enable multicast routing:</th><th align=left>",
- &radio('emr',$val{'emr'},"Yes","No"), "</th></tr><tr></tr>";
-
- print "<tr><th align=left>Setup IP tunnel (if needed):</th><th></th></tr>";
-
- print "</table>";
-
- print '<table cellpadding=5 width=350>';
-
- print '<tr><th align=left>Enable tunnel:</th>',
- '<td align=left><strong>';
- print &radio('tun',$val{'tun'},"Yes","No");
- print '</strong></td></tr>';
- print '<tr><th align=left>Interface:</th><td align=left>';
- print qq|<select name="int">|;
- for ($i=0;$i<=$#myInt;$i++) {
- if ($locIP ne $myIP[$i]) { print "<option>$myInt[$i] $myIP[$i]"; }
- else { print "<option selected>$myInt[$i] $myIP[$i]"; }
- }
- print "</select>";
- print '</td></tr><tr><th align=left>Remote IP address:</th><td align=left>';
- print &text('rip',$val{'rip'},14);
- print '</td></tr>';
- print '</table><br>';
-
- print &js_buttons('doit','Ok','onClick="markOK()"','onClick="markOther()"');
-
- print '</form>';
- }
-
- sub getInfo {
- undef @myInt;
- undef @myIP;
- open(IN, "/usr/OnRamp/bin/htnetwork |");
- while(<IN>) {
- @items = split(/:/);
- if ($items[3]) {
- push(@myInt,$items[1]);
- push(@myIP,$items[3]);
- }
- }
- close(IN);
-
- $val{'rip'} = "";
- $met = 1;
- $val{'tun'} = "No";
-
- $val{'emr'} = &get_config("mrouted");
-
- open(IN,"< $conf");
- while(<IN>) {
- @items = split(/\s+/);
- if ($items[0] ne 'tunnel') { next; }
- for($i=0;$i<=$#myIP;$i++) {
- if ($myIP[$i] eq $items[1]) {
- $val{'rip'} = $items[2];
- $locIP = $myIP[$i];
- $val{'tun'} = "Yes";
- }
- }
- }
- close(IN);
- }
-